package com.wyclabs.user.controller;

import com.wyclabs.api.UserResource;
import com.wyclabs.commons.entity.JsonResult;
import com.wyclabs.commons.request.UserCreateRequest;
import com.wyclabs.commons.response.UserResponse;
import com.wyclabs.user.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户
 * @author rs
 * @date 2019/10/10 21:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/user")
public class UserController implements UserResource {

    private final UserService userService;

    @Override
    @PostMapping("/create")
    public JsonResult create(@RequestBody UserCreateRequest request) {
        userService.create(request);
        return JsonResult.success();
    }

    @Override
    public JsonResult<UserResponse> findByUserName(String userName) {
        return JsonResult.success(userService.findByUserName(userName));
    }


    @Override
    public void test() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
